package com.ruoyi.kjy.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.kjy.domain.EnterpriseQualificationAwards;
import com.ruoyi.kjy.domain.IndustryAcademiaCollaboration;
import com.ruoyi.kjy.service.IEnterpriseQualificationAwardsService;
import com.ruoyi.kjy.service.IIndustryAcademiaCollaborationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Objects;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2024-12-09
 */
@RestController
@RequestMapping("/industry-academia-collaboration")
public class IndustryAcademiaCollaborationController extends BaseController {


    @Autowired
    private IIndustryAcademiaCollaborationService industryAcademiaCollaborationService;




    @GetMapping("/list")
    public AjaxResult list(Long current, Long size, IndustryAcademiaCollaboration industryAcademiaCollaboration) {
        QueryWrapper<IndustryAcademiaCollaboration> queryWrapper = new QueryWrapper<>();
        queryWrapper.setEntity(industryAcademiaCollaboration);
        if (Objects.isNull(current)) {
            current = 1l;
        }
        if (Objects.isNull(size)) {
            size = 10l;
        }
        if (size >= 20l) {
            size = 20l;
        }
        return AjaxResult.success(industryAcademiaCollaborationService.page(new Page<>(current, size), queryWrapper));
    }



    @GetMapping("/listByUserId")
    public AjaxResult listByUserId(Long current, Long size, IndustryAcademiaCollaboration industryAcademiaCollaboration) {
        QueryWrapper<IndustryAcademiaCollaboration> queryWrapper = new QueryWrapper<>();
        industryAcademiaCollaboration.setPublisherUserid(SecurityUtils.getUserId());
        queryWrapper.setEntity(industryAcademiaCollaboration);
        if (Objects.isNull(current)) {
            current = 1l;
        }
        if (Objects.isNull(size)) {
            size = 10l;
        }
        if (size >= 20l) {
            size = 20l;
        }
        return AjaxResult.success(industryAcademiaCollaborationService.page(new Page<>(current, size), queryWrapper));
    }





    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(industryAcademiaCollaborationService.getById(id));
    }


    @Log(title = "企业合作对象", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody IndustryAcademiaCollaboration industryAcademiaCollaboration) {

        industryAcademiaCollaboration.setPublisherUserid(SecurityUtils.getUserId());
        boolean save = industryAcademiaCollaborationService.save(industryAcademiaCollaboration);
        return toAjax(save);
    }

    @Log(title = "企业合作对象", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody IndustryAcademiaCollaboration industryAcademiaCollaboration) {

        return toAjax(industryAcademiaCollaborationService.updateById(industryAcademiaCollaboration));
    }

    @Log(title = "企业合作对象", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable(value = "ids") Long[] ids) {
        return toAjax(industryAcademiaCollaborationService.removeByIds(Arrays.asList(ids)));
    }

}
